package components.ghost;

import java.awt.Color;

import ai.Pathfinder;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.appearances.Appearance;
import com.uqbar.vainilla.appearances.Circle;
import components.direction.Direction;
import components.pacman.Pacman;
import components.scenes.MapMatrix;
import components.scenes.Slot;

public abstract class GhostState {

	private Ghost ghost;
	private Pathfinder pathfinder;

	
	public GhostState(Ghost ghost){
		this.setGhost(ghost);
		this.setPathfinder(Pathfinder.instance);
	}

	public Direction calculateNextDir(Slot nextSlot) {
		Slot currentSlot = new Slot(this.getGhost().getCurrentX(), this.getGhost().getCurrentY());
		
		if (nextSlot.getX() == currentSlot.getX()){
			if (nextSlot.getY() > currentSlot.getY()){
				return Direction.SOUTH;
			}else return Direction.NORTH;
		}else{
			if (nextSlot.getX() > currentSlot.getX()){
				return Direction.EAST;
			}else return Direction.WEST;
		}
	}
	
	public Ghost getGhost() {
		return ghost;
	}

	public void setGhost(Ghost ghost) {
		this.ghost = ghost;
	}
	
	public void chasing(){
		this.ghost.setState(new ChasingState(this.ghost));
	}
	public void scaping(int seconds){
		this.ghost.setState(new ScapingState(this.ghost, seconds));
	}
	

	public Pathfinder getPathfinder() {
		return pathfinder;
	}

	public void setPathfinder(Pathfinder pathfinder) {
		this.pathfinder = pathfinder;
	}
	protected MapMatrix getMapMatrix(){
		return this.getGhost().getScene().getMapMatrix();
	}

	public void update(DeltaState delta) {
	}

	public abstract double getSpeed();

	public void onCollisionWithPacman(Pacman pacman) {
		
	}

	public Appearance getAppaearance() {
		return new Circle(Color.GREEN, 20);
	}
}
